package com.cz.ssyx.product.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cz.ssyx.model.product.Category;
import com.cz.ssyx.model.product.SkuInfo;
import com.cz.ssyx.product.service.CategoryService;
import com.cz.ssyx.product.service.SkuInfoService;
import com.cz.ssyx.vo.product.SkuInfoVo;
import com.cz.ssyx.vo.product.SkuStockLockVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @descriptions:
 * @author: Joker.
 * @date: 2024/4/19 22:57
 * @version: 1.0
 */

@RestController
@RequestMapping("/api/product/inner")
public class ProductInnerController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private SkuInfoService skuInfoService;

    //获取分类信息
    @GetMapping("/getCategory/{categoryId}")
    public Category getCategoryById(@PathVariable Long categoryId) {
        return categoryService.getById(categoryId);
    }

    //获取商品信息
    @GetMapping("/getSkuInfo/{skuInfoId}")
    public SkuInfo getSkuInfoById(@PathVariable Long skuInfoId) {
        return skuInfoService.getById(skuInfoId);
    }

    //根据商品id列表返回商品信息列表
    @PostMapping("/findSkuInfoList")
    public List<SkuInfo> findSkuInfoList(@RequestBody List<Long> skuIdList) {
        return skuInfoService.findSkuInfoList(skuIdList);
    }

    //根据关键词查询商品信息
    @GetMapping("/findSkuInfoByKeyword/{keyword}")
    public List<SkuInfo> findSkuInfoByKeyword(@PathVariable String keyword) {
        return skuInfoService.findSkuInfoByKeyword(keyword);
    }

    //根据商品id列表返回商品信息列表
    @PostMapping("/findCategoryList")
    public List<Category> findCategoryList(@RequestBody List<Long> categoryIdList) {
        return categoryService.listByIds(categoryIdList);
    }

    //获取所有分类接口
    @GetMapping("/findAllCategoryList")
    public List<Category> findAllCategoryList() {
        return categoryService.list();
    }

    //获取所有新人专享商品
    @GetMapping("/findNewPersonSkuInfoList")
    public List<SkuInfo> findNewPersonSkuInfoList() {
        return skuInfoService.findNewPersonSkuInfoList();
    }

    //获取商品的所有信息
    @GetMapping("getSkuInfoVo/{skuId}")
    public SkuInfoVo getSkuInfoVoById(@PathVariable Long skuId) {
        return skuInfoService.getSkuInfoVoById(skuId);
    }

    //验证并锁定库存
    @PostMapping("checkAndLock/{orderNo}")
    public Boolean checkAndLock(@RequestBody List<SkuStockLockVo> skuStockLockVo,
                                @PathVariable String orderNo) {
        return skuInfoService.checkAndLock(skuStockLockVo, orderNo);
    }

    //因超时未付款释放库存
    @PostMapping("/timeOutUnLockStock")
    void timeOutUnLockStock(@RequestBody HashMap<Long, Integer> TimeoutOrderMap) {
         skuInfoService.releaseStock(TimeoutOrderMap);
    }
}
